import { Component, OnInit } from '@angular/core';
import { HttpService } from '../http.service';
import { UserService } from '../user.service';
import {ActivatedRoute} from '@angular/router';
import { Router } from '@angular/router';


@Component({
  selector: 'app-share',
  templateUrl: './share.component.html',
  styleUrls: ['./share.component.less']
})
export class ShareComponent implements OnInit {

  constructor(
    private user: UserService,
    private route: ActivatedRoute,
    private router: Router
  ) {
    this.user.getUserInfo().then(data => {
      // 若没有被扫码者id 则跳到自己id处
      const shareId = this.route.snapshot.params['id'];
      if(!shareId) this.router.navigate(['share', data.user_id], {replaceUrl:true});
      else this.user.getShareInfo(shareId).then(r => {
          if(!r.success) alert(r.msg);
      })
    })
  }

  get shareInfo() {
    return this.user.shareInfo.data;
  }
  get loading() {
    return !this.user.shareInfo.requestSent;
  }

  ngOnInit() {
  }

}
